package com.example.riseofthedefender;

import java.util.ArrayList;

import javax.microedition.khronos.opengles.GL10;

public class Soul{
	
	public static ArrayList<Soul> arrayList;
	public static void initArrayList(int size)
	{
		arrayList = new ArrayList<Soul>();
	}
	private static int i = 0;
	private static Soul object;
	public static boolean collideWith(float x, float y, float w, float h)
	{
		boolean collide = false;
		for(i = 0; i < arrayList.size(); ++i)
		{
			object = arrayList.get(i);
			if(x + w < object.left)
				continue;
			if(x > object.right)
				continue;
			if(y > object.top)
				continue;
			if(y + h < object.bottom)
				continue;
			
			--object.duration;
			
			collide = true;
		}
		return collide;
	}
	
	public float left;
	public float top;
	public float right;
	public float bottom;
	public float wHlv;
	public float hHlv;
	public float maxDuration = 60;
	public float duration = maxDuration;
	public int rotation = 0;
	
	public Soul(float left, float top, float right, float bottom)
	{
		this.left=left;
		this.top=top;
		this.right=right;
		this.bottom=bottom;
		wHlv = (right - left) * 0.5f;
		hHlv = (top - bottom) * 0.5f;
		arrayList.add(this);
		rotation = (int) (Math.random()*360);
	}
	
	public void draw(GL10 gl) {
		if(left>Camera.east || right<Camera.west || top < Camera.south || bottom > Camera.north)
			return;
		if(duration <=0)
			return;
		if(duration!=maxDuration)
			--duration;
		float scale = (duration/maxDuration);
		gl.glLoadIdentity();
		gl.glTranslatef(-Camera.pos.x,-Camera.pos.y,0.0f);
		gl.glTranslatef(left + wHlv, bottom + hHlv, 0.0f);
		gl.glBindTexture(GL10.GL_TEXTURE_2D, TextureManager.SOUL_1.textures[0]);
		gl.glScalef(wHlv*scale, hHlv*scale, 1.0f);
		gl.glRotatef(rotation+=3, 0, 0, 1);
		gl.glColor4f(1.0f, 1.0f, 1.0f, scale);
		gl.glDrawArrays(GL10.GL_TRIANGLE_STRIP, 0, Square.vertices.length / 3);
		gl.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
	}
}
